package cn.tedu.egnotice1.controller;

import cn.tedu.egnotice1.base.response.JsonResult;
import cn.tedu.egnotice1.mapper.NoticeMapper;
import cn.tedu.egnotice1.pojo.dto.NoticeAddParam;
import cn.tedu.egnotice1.pojo.dto.NoticeListQuery;
import cn.tedu.egnotice1.pojo.entity.Notice;
import cn.tedu.egnotice1.pojo.vo.NoticeListVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/v1/notice/")
public class NoticeController {
    @Autowired
    private NoticeMapper noticeMapper;
    @PostMapping("add")
    public JsonResult addNotice(NoticeAddParam noticeAddParam){
        Notice notice = new Notice();
        BeanUtils.copyProperties(noticeAddParam,notice);
        notice.setCreateTime(new Date());
        notice.setUpdateTime(new Date());
        notice.setUserId(1L);
        noticeMapper.addNotice(notice);
        return JsonResult.ok();
    }

    @GetMapping("list")
    public JsonResult selectNotice(NoticeListQuery noticeListQuery){
        String title = noticeListQuery.getTitle();
        Integer type = noticeListQuery.getType();
        System.out.println(title);
        System.out.println(type);
        List<NoticeListVO> list = noticeMapper.selectNotice(title, type);
        return JsonResult.ok(list);
    }
}
